/**
*  \file assertor_cfg.h
*
*  \brief Configuration of assertor exception handling.
*
*  \author Michael J. Hohmann <michael.hohmann@linde-mh.de>
*
*
*/

#ifndef ASSERTOR_CFG_H_INCLUDED
#define ASSERTOR_CFG_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include <stdlib.h>
#include <stdio.h>
#include "../deaddrop/deaddrop.h"
/*================================================[ public defines   ]================================================*/

void *hardware_get_trace_data_buffer(void);


static inline void ASSERTOR_function( CH* func, BO condition, const CH *condition_string,const CH *explanation, const CH* filename, U32 line, CH const * func_name )
{
   UNREFERENCED( condition_string );
   UNREFERENCED( func );
   UNREFERENCED( func_name );
   UNREFERENCED( condition_string );

	if( !condition )
	{
		snprintf( (CH*) hardware_get_trace_data_buffer(), DEADDROP_TRACE_DATA_SIZE, "%s:%u %s",filename,(unsigned int) line,explanation);
	   printf( "%s:%u: ASSERTOR_%s  %s", filename , (unsigned int) line, func,  explanation );
      asm("int $3"); /* set breakpoint */
		//exit(1);  /* Shuffle off this mortal coil. */
	}
}

#define ASSERTOR_ILLEGAL_DEFAULT_CALL( explanation )	ASSERTOR_function( "ILLEGAL_DEFAULT",  FALSE , "FALSE", explanation,  __FILE__, __LINE__, __func__ )

#define ASSERTOR_PRE_CALL(  condition, explanation ) 	ASSERTOR_function( "PRE",  condition, #condition, explanation,  __FILE__, __LINE__, __func__ )

#define ASSERTOR_CHK_CALL(  condition, explanation ) 	ASSERTOR_function( "CHK",  condition, #condition, explanation,  __FILE__, __LINE__, __func__ )

#define ASSERTOR_INV_CALL(  condition, explanation ) 	ASSERTOR_function( "INV",  condition, #condition, explanation,  __FILE__, __LINE__, __func__ )

#define ASSERTOR_POST_CALL( condition, explanation ) 	ASSERTOR_function( "POST", condition, #condition, explanation,  __FILE__, __LINE__, __func__ )

/*================================================[ public datatypes ]================================================*/

/*================================================[ public variables ]================================================*/

/*================================================[ public functions ]================================================*/

/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2014 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
